package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dtos.ModuloDTO;
import dtos.ServiciosModuloDTO;

@WebServlet("/BuscarModulos")
public class BuscarModulos extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	private bd.BusinessDelegate bd = null;
	private List<ModuloDTO> resultado = null;
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BuscarModulos() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = response.getWriter();
		out.println("<table width='100%' cellspacing='5' cellpading='5'>");
		resultado = bd.getInstance().getModulos();
		String servicios= "";
		for(ModuloDTO aux : resultado){
			out.println("<tr width='100%'>");
			out.println("<td width='5%'> <img src='images/editar.png' border='0' title='Editar' style='cursor: pointer;' onclick='editar(" + aux.getId() + ");'></img></td>");
			out.println("<td width='5%'>"+aux.getId()+"</td>");
			out.println("<td width='20%'>"+aux.getNombre()+"</td>");
			out.println("<td width='10%'>"+aux.getIp()+"</td>");
			servicios = "";
			for (ServiciosModuloDTO serAux: aux.getServicios()){
				servicios += serAux.getPath() + " - ";
			}
			out.println("<td width='40%'>" + servicios +"</td>");
			out.println("<td width='8%'>" + aux.isActivo() +"</td>");
			out.println("</tr>");
			}
		out.println("</table>");
	}

}
